package com.fhzn.boss.tools;


import org.apache.commons.lang3.StringUtils;

import java.util.Random;


/**
 * @author fhzn
 */
public class RandomUtil {

    /**
     * 包含有数字和字符的字符串
     */
    public static final String LETTER_NUMBER = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    /**
     * 包含有数字和字符的字符串
     */
    public static final String LETTER_NUMBER_SYMBOL = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&";

    /**
     * 去掉易混淆到字母
     */
    public static final String SIMPLE_LETTER_NUMBER_SYMBOL = "abcdefghkmnopqrstuvwxyABCDEFGHJKLMNPQRSTUVWXY23456789@#%&";


    /**
     * 获得随机的字母和数字组合
     *
     * @return 字符串
     */
    public static String getRandomLetterAndNumber(int length) {
        if (length <= 0) {
            return StringUtils.EMPTY;
        }
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            sb.append(LETTER_NUMBER.charAt(random.nextInt(LETTER_NUMBER.length())));
        }
        return sb.toString();
    }

    /**
     * 获得随机的字母和数字组合
     *
     * @return 字符串
     */
    public static String getRandomLetterAndNumberAndSymbol(int length) {
        if (length <= 0) {
            return StringUtils.EMPTY;
        }
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            sb.append(LETTER_NUMBER_SYMBOL.charAt(random.nextInt(LETTER_NUMBER_SYMBOL.length())));
        }
        return sb.toString();
    }

    /**
     * 去掉易混淆的字母
     *
     * @return 字符串
     */
    public static String getSimpleLetterNumberSymbol(int length) {
        if (length <= 0) {
            return StringUtils.EMPTY;
        }
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            sb.append(SIMPLE_LETTER_NUMBER_SYMBOL.charAt(random.nextInt(SIMPLE_LETTER_NUMBER_SYMBOL.length())));
        }
        return sb.toString();
    }

}
